package com.system.transfer.web;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.system.common.util.ExtAjaxResponse;
import com.system.common.util.ExtPageable;
import com.system.employee.entity.Employee;
import com.system.employee.service.IEmployeeService;
import com.system.transfer.entity.Transfer;
import com.system.transfer.entity.dto.TransferDTO;

import com.system.transfer.service.ITransferService;
@Controller
@RequestMapping("/transfer")
public class TransferController {
	@Autowired
	private ITransferService transferService;

	@RequestMapping("/saveOrUpdate")
	public @ResponseBody ExtAjaxResponse saveOrUpdate(Transfer transfer) {
		
		
		try {
			transferService.saveOrUpdate(transfer);
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			System.out.println(e);
			return new ExtAjaxResponse(false,"操作失败");
		}
		
		
	}
	@RequestMapping("/delete")
	public @ResponseBody ExtAjaxResponse delete(Transfer transfer) {
	
		try {
			transferService.delete(transfer);
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	
	}
	
	@RequestMapping("/deleteTransfers")
	public @ResponseBody ExtAjaxResponse deleteTransfers(@RequestParam Long[] ids) {
	
		try {
			List<Long> idLists = Arrays.asList(ids);
			transferService.delete(idLists);
			return new ExtAjaxResponse(true,"操作成功！");
		} catch (Exception e) {
			return new ExtAjaxResponse(false,"操作失败！");
		}
	
	}
	
	@RequestMapping("/findPage")
	public @ResponseBody Page<Transfer> findPage(TransferDTO transferDTO,ExtPageable pageable) 
	{
		Page<Transfer> page =  transferService.findPage(TransferDTO.getTransferPage(transferDTO),pageable.getPageable());
		
		return page;
	}
	
	
}
